/**
 * AppDeviceMapper.java 
 * Copyright © 2009-2014, Liu Tao
 * 
 * @author Liu Tao
 * @create 2014年5月18日
 */
package com.pshare.appdevice.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.pshare.appdevice.bean.AppDevice;
import com.pshare.framework.mapper.BaseMapper;

/**
 * 客户端设备持久层
 */
public interface AppDeviceMapper extends BaseMapper<Long, AppDevice> {

	@Select("select * from tbl_app_device where device_token = #{deviceToken}")
	public AppDevice getDeviceByToken(@Param("deviceToken") String deviceToken);

	public void updateUnread(Map<String, Object> params);

	@Insert("insert into tbl_app_device (id, user_id, os_type, biz_client_type, model, device_token) "
			+ "values (#{id}, #{userId}, #{osType}, #{bizClientType}, #{model}, #{deviceToken})")
	@Options(useGeneratedKeys = true, keyProperty = "id")
	public int add(AppDevice appDevice);

	public void addUnreadCount(@Param("list") List<String> list, @Param("count") Integer count);

	public void delete(@Param("userId") Long userId, @Param("deviceToken") String deviceToken);

	@Update("update tbl_app_device set deleted = 1 where datediff(now(), login_time) > #{days}")
	public void clearOverTimeDeviceToken(@Param("days") Integer days);

}
